<span class="glyphicon glyphicon-map-marker" aria-hidden="true">
    <span>系统</span> /
    <span>商品管理</span> /
    <span>商品品牌列表</span>
</span>
<style>
    select{
        margin-left: 15px;
        width: 15%;
        height: 34px;
        padding: 6px 12px;
        font-size: 14px;
        line-height: 1.42857143;
        color: #555;
        background-color: #fff;
        background-image: none;
        border: 1px solid #ccc;
        border-radius: 4px;
        -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075);
        box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075);
        -webkit-transition: border-color ease-in-out .15s, -webkit-box-shadow ease-in-out .15s;
        -o-transition: border-color ease-in-out .15s, box-shadow ease-in-out .15s;
        transition: border-color ease-in-out .15s, box-shadow ease-in-out .15s;
    }
    .btn{
        padding: 7px 18px;
        margin-right: 6px;
    }
</style>
<div style="width: 100%;margin-top: 20px;">
    <div style="display: flex; width: 100%;min-width: 800px;">
        <a name="add" title="添加" class="btn edit-btn" href="{:url('Admin/GoodsType/Add')}">添加</a>
    </div>
    <div class="table-responsive" style="border:0px solid #fff;">
        <table class="table table-hover"  border="1" width="100%" cellpadding="0" cellspacing="0" style="margin: 20px 0px;">
            <tr>
                <td width="25%" style="vertical-align: middle;">分类名称</td>
                <td width="25%" style="vertical-align: middle;">分类logo</td>
                <td width="25%" style="vertical-align: middle;">排序顺序</td>
                <td style="vertical-align: middle;">操作</td>
            </tr>
            {volist name="list" id="vo"}
            <tr>
                <td style="vertical-align: middle;padding-left: -50px;">
                    {$vo.title}
                </td>
                <td style="text-align: center;vertical-align: middle;">
                    {if condition="$vo.UploadLogo != null"}
                    <img src="__IMG__{$vo.UploadLogo.path}" style="max-width: 200px;max-height: 40px;"
                         data-target="#modal" data-toggle="modal" onclick="getPicture('{$vo.logo}')" />
                    {/if}
                </td>
                <td style="text-align: center;vertical-align: middle;">
                    <input type="number" step="1" min="0" value="{$vo.sort}"
                           id="sort-{$vo.id}" name="sort-{$vo.id}" class="form-control"
                           onblur="getSort({$vo.id})"  />
                </td>
                <td style="text-align: center;vertical-align: middle;">
                    <a name="edit" title="编辑" class="btn edit-btn"
                       href="{:url('Admin/Goods_type/edit')}?id={$vo.id}">编辑</a>
                    <a name="delete" title="删除" class="btn delete-btn" id="operation{$vo.id}"
                       onclick="goodsTypeDelete('{$vo.id}')">删除</a>
                </td>
            </tr>
            {volist name="vo.TypeId" id="vo"}
            <tr>
                <td style="text-align: center;vertical-align: middle;"> &nbsp;&nbsp;&nbsp;&nbsp;┣ &nbsp;&nbsp;&nbsp;&nbsp;{$vo.title}</td>
                <td style="text-align: center;vertical-align: middle;">
                    {if condition="$vo.UploadLogo != null"}
                    <img src="__IMG__{$vo.UploadLogo.path}" style="max-width: 200px;max-height: 40px;"
                         data-target="#modal" data-toggle="modal" onclick="getPicture('{$vo.logo}')" />
                    {/if}
                </td>
                <td style="text-align: center;vertical-align: middle;">
                    <input type="number" step="1" min="0" value="{$vo.sort}"
                           id="sort-{$vo.id}" name="sort-{$vo.id}" class="form-control"
                           onblur="getSort({$vo.id})"  />
                </td>
                <td style="text-align: center;vertical-align: middle;">
                    <a name="edit" title="编辑" class="btn edit-btn"
                       href="{:url('Admin/GoodsType/edit')}?id={$vo.id}">编辑</a>
                    <a name="delete" title="删除" class="btn delete-btn" id="operation{$vo.id}"
                       onclick="goodsTypeDelete('{$vo.id}')">删除</a>
                </td>
            </tr>
            {/volist}
            {/volist}
        </table>
        {$list->render()}
    </div>
</div>
<script type="text/javascript">
    function queryOrder() {
        var user_id = document.getElementById("user_id").value;
        window.location.href = "{:url('Admin/GoodsType/Index')}?user_id="+user_id;
    }
    //排序
    function getSort(id) {
        var sort = $("input[id='sort-"+id+"']").val();
        if(sort <= 0){
            sort = 1;
        }
        var json = {id:id,sort:sort};
        console.log(json);
        $.ajax({
            type:"post",
            url:"{:url('Admin/GoodsType/sort')}",
            data:json,
            success:function (res) {
                if(res == "排序成功"){
                    // success(res);
                    // setTimeout("location_href()",2000);
                    return;
                }
                msg(res);
                if(res == "请重新登录"){
                    setTimeout("location_href()",2000);
                    return;
                }
            }
        });
    }
    //删除操作
    function goodsTypeDelete(id) {
        layer.confirm('请确认是否删除', {
            icon: 3,btn: ['确认','取消'] //按钮
        }, function(){
            $.ajax({
                type:"POST",
                url:"{:url('Admin/GoodsType/Delete')}",
                data:{id:id},
                success:function (res) {
                    if(res == "删除成功"){
                        msg(res);
                        setTimeout("location_href()",3000);
                        return;
                    }
                    msg(res);
                    if(res == "请重新登录"){
                        setTimeout("location_href()",3000);
                        return;
                    }
                }
            });
        }, function () {
            layer.msg('取消操作');
        });
    }
</script>